<template>
	<view class="tabbar" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
		<view class="tabbar-item" v-for="(item, index) in list" :key="index" @click="tabbarChange(item.path)">
			<image class="item-img" :src="item.icon_c" v-if="current == item.id"></image>
			<image class="item-img" :src="item.icon" v-else></image>
			<view class="item-name" :class="{'tabbarActive': current == item.id}" v-if="item.text">{{item.text}}
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		name: "tabbar",
		components: {},
		props: ['current'],
		data() {
			return {
				paddingBottomHeight: 0, //苹果X以上手机底部适配高度
				list: [],
			}
		},
		created() {
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
					model.forEach(item => {
						//适配iphoneX以上的底部，给tabbar一定高度的padding-bottom
						if (res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
							that.paddingBottomHeight = 0;
						}
					})
				}
			});
			this.getUserAuth()
		},
		mounted() {
			this.$on("childmethod", function() {
				this.getUserAuth()
			})
		},
		methods: {
			async getUserAuth() {
				if (!uni.getStorageSync("token")) {
					this.list = [{
							"path": "/pages/tabbar/tab-1",
							"icon": "/static/tabBar/index.png",
							"icon_c": "/static/tabBar/index_active.png",
							"text": "首页",
							id: 0
						},
						{
							"path": "/pages/tabbar/tab-2",
							"icon": "/static/tabBar/two.png",
							"icon_c": "/static/tabBar/two_active.png",
							"text": "招聘",
							id: 1
						},
						{
							"path": "/pages/tabbar/news",
							"icon": "/static/tabBar/new.png",
							"icon_c": "/static/tabBar/news.png",
							"text": "消息",
							id: 4
						},
						{
							"path": "/pages/tabbar/tab-4",
							"icon": "/static/tabBar/zixun.png",
							"icon_c": "/static/tabBar/zixun_active.png",
							"text": "我的",
							id: 3
						}
					]
					return false
				};
				const data = await this.http.get("index/getConfigInfo");
				// is_showjob 0全部显示 1隐藏 2在职 3离职
				// is_zpshowstatus 0全部显示 1隐藏 2离职人员显示
				// is_wyshowjob:0文员,1不是文员
				if ((data.data.is_wyshowjob == 0 && (uni.getStorageSync("group_id") == 3||uni.getStorageSync("group_id") == 2)) || data.data.is_wyshowjob ==
					1) {
					if (data.data.is_showjob != 1) {
						if(data.data.is_zpshowstatus==0 || data.data.is_zpshowstatus==2){
							this.list = [{
									"path": "/pages/tabbar/tab-1",
									"icon": "/static/tabBar/index.png",
									"icon_c": "/static/tabBar/index_active.png",
									"text": "首页",
									id: 0
								},
								{
									"path": "/pages/tabbar/tab-2",
									"icon": "/static/tabBar/two.png",
									"icon_c": "/static/tabBar/two_active.png",
									"text": "招聘",
									id: 1
								},
								{
									"path": "/pages/tabbar/tab-3",
									"icon": "/static/tabBar/four.png",
									"icon_c": "/static/tabBar/four_active.png",
									"text": "人脉",
									id: 2
								},
								{
									"path": "/pages/tabbar/news",
									"icon": "/static/tabBar/new.png",
									"icon_c": "/static/tabBar/news.png",
									"text": "消息",
									id: 4
								},
								{
									"path": "/pages/tabbar/tab-4",
									"icon": "/static/tabBar/zixun.png",
									"icon_c": "/static/tabBar/zixun_active.png",
									"text": "我的",
									id: 3
								}
							]
						}else{
							this.list = [{
									"path": "/pages/tabbar/tab-1",
									"icon": "/static/tabBar/index.png",
									"icon_c": "/static/tabBar/index_active.png",
									"text": "首页",
									id: 0
								},
								{
									"path": "/pages/tabbar/tab-3",
									"icon": "/static/tabBar/four.png",
									"icon_c": "/static/tabBar/four_active.png",
									"text": "人脉",
									id: 2
								},
								{
									"path": "/pages/tabbar/news",
									"icon": "/static/tabBar/new.png",
									"icon_c": "/static/tabBar/news.png",
									"text": "消息",
									id: 4
								},
								{
									"path": "/pages/tabbar/tab-4",
									"icon": "/static/tabBar/zixun.png",
									"icon_c": "/static/tabBar/zixun_active.png",
									"text": "我的",
									id: 3
								}
							]
						}
						
						console.log("已经离职》》》》》》》》》》");

					} else {
						if(data.data.is_zpshowstatus==0 || data.data.is_zpshowstatus==2){
							this.list = [{
									"path": "/pages/tabbar/tab-1",
									"icon": "/static/tabBar/index.png",
									"icon_c": "/static/tabBar/index_active.png",
									"text": "首页",
									id: 0
								},
								{
									"path": "/pages/tabbar/tab-2",
									"icon": "/static/tabBar/two.png",
									"icon_c": "/static/tabBar/two_active.png",
									"text": "招聘",
									id: 1
								},
								{
									"path": "/pages/tabbar/news",
									"icon": "/static/tabBar/new.png",
									"icon_c": "/static/tabBar/news.png",
									"text": "消息",
									id: 4
								},
								{
									"path": "/pages/tabbar/tab-4",
									"icon": "/static/tabBar/zixun.png",
									"icon_c": "/static/tabBar/zixun_active.png",
									"text": "我的",
									id: 3
								}
							]
						}else{
							this.list = [{
									"path": "/pages/tabbar/tab-1",
									"icon": "/static/tabBar/index.png",
									"icon_c": "/static/tabBar/index_active.png",
									"text": "首页",
									id: 0
								},
								{
									"path": "/pages/tabbar/news",
									"icon": "/static/tabBar/new.png",
									"icon_c": "/static/tabBar/news.png",
									"text": "消息",
									id: 4
								},
								{
									"path": "/pages/tabbar/tab-4",
									"icon": "/static/tabBar/zixun.png",
									"icon_c": "/static/tabBar/zixun_active.png",
									"text": "我的",
									id: 3
								}
							]
						}
						
						console.log("已经在职》》》》》》》》》》");
					}
				} else {
					this.list = [{
							"path": "/pages/tabbar/tab-1",
							"icon": "/static/tabBar/index.png",
							"icon_c": "/static/tabBar/index_active.png",
							"text": "首页",
							id: 0
						},
						{
							"path": "/pages/tabbar/tab-2",
							"icon": "/static/tabBar/two.png",
							"icon_c": "/static/tabBar/two_active.png",
							"text": "招聘",
							id: 1
						},
						{
							"path": "/pages/tabbar/news",
							"icon": "/static/tabBar/new.png",
							"icon_c": "/static/tabBar/news.png",
							"text": "消息",
							id: 4
						},
						{
							"path": "/pages/tabbar/tab-4",
							"icon": "/static/tabBar/zixun.png",
							"icon_c": "/static/tabBar/zixun_active.png",
							"text": "我的",
							id: 3
						}
					]
					console.log("已经在职》》》》》》》》》》");
				}
			},
			tabbarChange(path) {
				uni.switchTab({
					url: path
				})
			}
		}

	}
</script>

<style lang="scss">
	.item-img {
		height: 40rpx;
		width: 40rpx;
		margin: auto;
		display: block;
	}

	// .fabuimg{
	// 	position: absolute;
	// 	bottom: 36rpx;
	// 	left: 10rpx;
	// 	height: 90rpx;
	// 	width: 90rpx;
	// 	margin: auto;
	// 	display: block;
	// 	background-color: #fff;
	// 	background-size: 80rpx 80rpx;
	// 	border-radius: 50%;
	// 	// box-shadow: 0px -5px 5px 0px rgba(0, 0, 0, 0.05);
	// }

	.tabbar {
		display: flex;
		justify-content: space-around;
		align-items: flex-end;
		background: #FFFFFF;
		border-radius: 0rpx;
		/* #ifdef MP-WEIXIN */
		height: 125rpx;
		/* #endif */
		/* #ifdef H5 */
		height: 125rpx;
		/* #endif */
		/* #ifdef APP-PLUS */
		height: 125rpx;
		/* #endif */
		// padding: 0 50rpx 0 50rpx;
		box-sizing: border-box;
		position: fixed;
		width: 100%;
		bottom: 0;
		overflow: inherit;
		z-index: 100;
		// box-shadow: 0px -2px 4px 1px rgba(0, 0, 0, 0.05);
	}

	.tabbar-item {
		margin-bottom: 30rpx;
		width: 250rpx;
		position: relative;
	}

	.item-name {
		font-size: 24rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		text-align: center;
		color: #888;
		margin-top: 14rpx;
	}

	.tabbarActive {
		color: #c1282e;
		text-align: center;
	}
</style>